package com.zsummer.demo.spring.rabbitmq.workqueue;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author zsummer
 * @since 2021/12/28
 */

@Component
public class WorkQueueConsuemr1 {

    /**
     * ackMode 确认机制，支持 NONE，MANUAL， AUTO
     */
    @RabbitListener(queues = "workqueue", ackMode = "MANUAL")
    public void handle(String msg, Message message, Channel channel) throws IOException {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("consumer1 " + msg);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
